package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysAssetProcurementPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysAssetProcurementPlan;
import com.ruoyi.system.service.ISysAssetProcurementPlanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购计划Controller
 * 
 * @author sxy
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/plan")
public class SysAssetProcurementPlanController extends BaseController
{
    @Autowired
    private ISysAssetProcurementPlanService sysAssetProcurementPlanService;

    /**
     * 查询采购计划列表
     */
    @RequiresPermissions("system:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(SysAssetProcurementPlan sysAssetProcurementPlan)
    {
        startPage();
        List<SysAssetProcurementPlanVo> list = sysAssetProcurementPlanService.selectSysAssetProcurementPlanList(sysAssetProcurementPlan);
        return getDataTable(list);
    }

    /**
     * 导出采购计划列表
     */
    @RequiresPermissions("system:plan:export")
    @Log(title = "采购计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAssetProcurementPlan sysAssetProcurementPlan)
    {
        List<SysAssetProcurementPlanVo> list = sysAssetProcurementPlanService.selectSysAssetProcurementPlanList(sysAssetProcurementPlan);
        ExcelUtil<SysAssetProcurementPlanVo> util = new ExcelUtil<SysAssetProcurementPlanVo>(SysAssetProcurementPlanVo.class);
        util.exportExcel(response, list, "采购计划数据");
    }

    /**
     * 获取采购计划详细信息
     */
    @RequiresPermissions("system:plan:query")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(sysAssetProcurementPlanService.selectSysAssetProcurementPlanByPlanId(planId));
    }

    /**
     * 新增采购计划
     */
    @RequiresPermissions("system:plan:add")
    @Log(title = "采购计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAssetProcurementPlan sysAssetProcurementPlan)
    {
        return toAjax(sysAssetProcurementPlanService.insertSysAssetProcurementPlan(sysAssetProcurementPlan));
    }

    /**
     * 修改采购计划
     */
    @RequiresPermissions("system:plan:edit")
    @Log(title = "采购计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAssetProcurementPlan sysAssetProcurementPlan)
    {
        return toAjax(sysAssetProcurementPlanService.updateSysAssetProcurementPlan(sysAssetProcurementPlan));
    }

    /**
     * 删除采购计划
     */
    @RequiresPermissions("system:plan:remove")
    @Log(title = "采购计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(sysAssetProcurementPlanService.deleteSysAssetProcurementPlanByPlanIds(planIds));
    }
}
